﻿using System;
using System.Runtime.Serialization;

namespace ExFlash.Filters
{
    public enum FilterTypes: byte
    {
        HasDropShadowFilter = 0,
        HasBlurFilter = 1,
        HasGlowFilter = 2,
        HasBevelFilter = 3,
        HasGradientGlowFilter = 4,
        HasConvolutionFilter = 5,
        HasColorMatrix = 6,
        HasGradientBevelFilter = 7
    }
    
    public class Filter : ISwfSerializable
    {
        public FilterTypes FilterId
        {
            get;
            private set;
        }

        public DropShadowFilter DropShadowFilter
        {
            get;
            private set;
        }

        public BlurFilter BlurFilter
        {
            get;
            private set;
        }

        public GlowFilter GlowFilter
        {
            get;
            private set;
        }

        public BevelFilter BevelFilter
        {
            get;
            private set;
        }

        public GradientGlowFilter GradientGlowFilter
        {
            get;
            private set;
        }

        public ConvolutionFilter ConvolutionFilter
        {
            get;
            private set;
        }

        public ColorMatrixFilter ColorMatrixFilter
        {
            get;
            private set;
        }

        public GradientBevelFilter GradientBevelFilter
        {
            get;
            private set;
        }

        #region ISwfSerializable Members

        public void SwfDeserialize(BinaryBitReader reader)
        {
            FilterId = (FilterTypes)reader.ReadByte();

            switch (FilterId)
            {
                case FilterTypes.HasDropShadowFilter:
                    {
                        DropShadowFilter = new DropShadowFilter();
                        DropShadowFilter.SwfDeserialize(reader);
                        break; 
                    }
                case FilterTypes.HasBlurFilter:
                    {
                        BlurFilter = new BlurFilter();
                        BlurFilter.SwfDeserialize(reader);
                        break;
                    }
                case FilterTypes.HasGlowFilter:
                    {
                        GlowFilter = new GlowFilter();
                        GlowFilter.SwfDeserialize(reader);
                        break;
                    }
                case FilterTypes.HasBevelFilter:
                    {
                        BevelFilter = new BevelFilter();
                        BevelFilter.SwfDeserialize(reader);
                        break;
                    }
                case FilterTypes.HasGradientGlowFilter:
                    {
                        GradientGlowFilter = new GradientGlowFilter();
                        GradientGlowFilter.SwfDeserialize(reader);
                        break;
                    }
                case FilterTypes.HasConvolutionFilter:
                    {
                        ConvolutionFilter = new ConvolutionFilter();
                        ConvolutionFilter.SwfDeserialize(reader);
                        break;
                    }
                case FilterTypes.HasColorMatrix:
                    {
                        ColorMatrixFilter = new ColorMatrixFilter();
                        ColorMatrixFilter.SwfDeserialize(reader);
                        break;
                    }
                case FilterTypes.HasGradientBevelFilter:
                    {
                        GradientBevelFilter = new GradientBevelFilter();
                        GradientBevelFilter.SwfDeserialize(reader);
                        break;
                    }
                default:
                    {
                        throw new SerializationException("Error when deserializing Filter - Unknown Filter ID");
                    }
            }
             
        }

        public void SwfSerialize(byte[] arr, ref int offset)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
